package response

import "net/http"
import "github.com/gin-gonic/gin"

type Response struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

const (
	successCode = http.StatusOK
	failedCode  = http.StatusBadRequest
)

func Success(c *gin.Context, data interface{}) {
	c.JSON(successCode, Response{
		successCode,
		"success",
		data,
	})
}

func Fail(c *gin.Context, data interface{}) {
	c.JSON(failedCode, Response{
		failedCode,
		"fail",
		data,
	})
}

func Error(c *gin.Context, code int, message string, data interface{}) {
	c.JSON(code, Response{
		code,
		"fail",
		data,
	})
}
